﻿#region << 文件说明 >>

/*----------------------------------------------------------------
 * 命名空间：Vampirewal.Core.FlowEngine.Internal
 * 唯一标识：a34acfd9-7b0d-4b1e-944d-679565a9ba54
 * 文件名：VampirewalFlowBuilder
 *
 * 创建者：杨程
 * 电子邮箱：235160615@qq.com
 * 创建时间：2023/10/27 17:34:35
 * 版本：V1.0.0
 * 描述：
 *
 * ----------------------------------------------------------------
 * 修改人：
 * 时间：
 * 修改说明：
 *
 * 版本：V1.0.1
 *----------------------------------------------------------------*/

#endregion << 文件说明 >>

namespace Vampirewal.Core.FlowEngine;

/// <summary>
/// 流程引擎构造器
/// </summary>
internal class VampirewalFlowBuilder : IVampirewalFlowBuilder
{
    internal Flow FlowInfo { get; set; }
    internal List<FlowParam> ParamInfo { get; set; }

    public VampirewalFlowBuilder()
    {
        FlowInfo = new Flow()
        {
            BillId = Guid.NewGuid().ToString(),
            State = 1,
        };

        ParamInfo = new List<FlowParam>();
    }

    /// <summary>
    /// 设置流程基本信息
    /// </summary>
    /// <param name="FlowCode">流程Code编号</param>
    /// <param name="Description">描述</param>
    /// <param name="FlowType">流程类型</param>
    /// <param name="Nodes">配置流程节点</param>
    public Flow Builder(string FlowCode, string Description, int FlowType, Action<IVampirewalFlowNodeOption, List<FlowParam>> Option)
    {
        FlowInfo.FlowCode = FlowCode;
        FlowInfo.Description = Description;
        FlowInfo.FlowType = FlowType;

        VampirewalFlowNodeOption nodeOption = new VampirewalFlowNodeOption(FlowInfo);

        Option.Invoke(nodeOption, ParamInfo);

        foreach (var item in ParamInfo)
        {
            FlowParam par = new FlowParam()
            {
                DtlId = Guid.NewGuid().ToString(),
                BillId = FlowInfo.BillId,
                ParameterName = item.ParameterName,
                ValueType = item.ValueType,
            };

            FlowInfo.Parameters.Add(par);
        }

        FlowInfo.Units = nodeOption.Units;
        FlowInfo.Links = nodeOption.Links;

        return FlowInfo;
    }
}